import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

if __name__ == '__main__':
    """招聘公告发布数量折线图（按周）"""
    df = pd.read_csv('../campus_20241108_20231107.csv')
    df['date'] = pd.to_datetime(df['date'])
    df['week'] = df['date'] - pd.to_timedelta(df['date'].dt.weekday, unit='D')
    df['week'] = df['week'].dt.date
    df = df[df['date'] > '2023-11-01']
    df = df[df['date'] < '2024-11-01']
    campus = df.groupby('week')['title'].count()
    full_date_range = pd.date_range(start='2023-11-01', end='2024-11-01', freq='W-MON')
    campus = campus.reindex(full_date_range).fillna(0)
    plt.figure()
    plt.plot(campus.index, campus, 'o-b')
    matplotlib.rcParams['font.sans-serif'] = 'KaiTi'
    plt.title('招聘公告发布数量')
    plt.xlabel('时间')
    plt.ylabel('数量（一周）')
    plt.grid()
    plt.show()
